package utils;

import android.text.TextUtils;
import android.util.Log;

import java.text.Collator;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;

import beans.LogBean;
import beans.ReturnHintBean;
import constants.HandlerConstant;
import customhandler.MyHandler;
import singleton.SingletonClass;

/**
 * Created by Administrator on 2018/8/13.
 */

public class LogSortUtils {
    public static MyHandler allHandler = SingletonClass.getSingleton(MyHandler.class);

    public static void sortLogName(List<LogBean.LogDetailBean> list, boolean flag) {
        if (flag) {
            Collections.sort(list, new Comparator<LogBean.LogDetailBean>() {
                @Override
                public int compare(LogBean.LogDetailBean o1, LogBean.LogDetailBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    String name1 = o1.getName();
                    String name2 = o2.getName();
                    if (TextUtils.isEmpty(o1.getName())) {
                        name1 = "阿阿阿阿";
                    }
                    if (TextUtils.isEmpty(o2.getName())) {
                        name2 = "阿阿阿阿";
                    }
                    if (ca.compare(name2, name1) < 0) {
                        return 1;
                    } else if (ca.compare(name2, name1) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<LogBean.LogDetailBean>() {
                @Override
                public int compare(LogBean.LogDetailBean o1, LogBean.LogDetailBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    String name1 = o1.getName();
                    String name2 = o2.getName();
                    if (TextUtils.isEmpty(o1.getName())) {
                        name1 = "阿阿阿阿";
                    }
                    if (TextUtils.isEmpty(o2.getName())) {
                        name2 = "阿阿阿阿";
                    }
                    if (ca.compare(name2, name1) > 0) {
                        return 1;
                    } else if (ca.compare(name2, name1) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }
    }

    public static void sortLogCabinet(List<LogBean.LogDetailBean> list, boolean flag) {
        if (flag) {
            Collections.sort(list, new Comparator<LogBean.LogDetailBean>() {
                @Override
                public int compare(LogBean.LogDetailBean o1, LogBean.LogDetailBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getLogicNumber(), o1.getLogicNumber()) < 0) {
                        return 1;
                    } else if (ca.compare(o2.getLogicNumber(), o1.getLogicNumber()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<LogBean.LogDetailBean>() {
                @Override
                public int compare(LogBean.LogDetailBean o1, LogBean.LogDetailBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getLogicNumber(), o1.getLogicNumber()) > 0) {
                        return 1;
                    } else if (ca.compare(o2.getLogicNumber(), o1.getLogicNumber()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }
    }

    public static void sortLogDept(List<LogBean.LogDetailBean> list, boolean flag) {
        if (flag) {
            Collections.sort(list, new Comparator<LogBean.LogDetailBean>() {
                @Override
                public int compare(LogBean.LogDetailBean o1, LogBean.LogDetailBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    String name1 = o1.getDepartment();
                    String name2 = o2.getDepartment();
                    if (TextUtils.isEmpty(name1)) {
                        name1 = "阿阿阿阿";
                    }
                    if (TextUtils.isEmpty(name2)) {
                        name2 = "阿阿阿阿";
                    }
                    if (ca.compare(name2, name1) < 0) {
                        return 1;
                    } else if (ca.compare(name2, name1) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<LogBean.LogDetailBean>() {
                @Override
                public int compare(LogBean.LogDetailBean o1, LogBean.LogDetailBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    String name1 = o1.getDepartment();
                    String name2 = o2.getDepartment();
                    if (TextUtils.isEmpty(name1)) {
                        name1 = "阿阿阿阿";
                    }
                    if (TextUtils.isEmpty(name2)) {
                        name2 = "阿阿阿阿";
                    }
                    if (ca.compare(name2, name1) > 0) {
                        return 1;
                    } else if (ca.compare(name2, name1) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }
    }

    public static void sortLogRole(List<LogBean.LogDetailBean> list, boolean flag) {
        if (flag) {
            Collections.sort(list, new Comparator<LogBean.LogDetailBean>() {
                @Override
                public int compare(LogBean.LogDetailBean o1, LogBean.LogDetailBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    String name1 = o1.getRoleInfo();
                    String name2 = o2.getRoleInfo();
                    if (TextUtils.isEmpty(name1)) {
                        name1 = "阿阿阿阿";
                    }
                    if (TextUtils.isEmpty(name2)) {
                        name2 = "阿阿阿阿";
                    }
                    if (ca.compare(name2, name1) < 0) {
                        return 1;
                    } else if (ca.compare(name2, name1) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<LogBean.LogDetailBean>() {
                @Override
                public int compare(LogBean.LogDetailBean o1, LogBean.LogDetailBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    String name1 = o1.getRoleInfo();
                    String name2 = o2.getRoleInfo();
                    if (TextUtils.isEmpty(name1)) {
                        name1 = "阿阿阿阿";
                    }
                    if (TextUtils.isEmpty(name2)) {
                        name2 = "阿阿阿阿";
                    }
                    if (ca.compare(name2, name1) > 0) {
                        return 1;
                    } else if (ca.compare(name2, name1) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }
    }

    public static void sortLogTime(final List<LogBean.LogDetailBean> list, final boolean flag) {
        if (flag) {
            Collections.sort(list, new Comparator<LogBean.LogDetailBean>() {
                @Override
                public int compare(LogBean.LogDetailBean o1, LogBean.LogDetailBean o2) {
                    long time1 = Long.parseLong(TimeUtil.dateToStampSeconds(TimeUtil.getTime(o1.getSubTime())));
                    long time2 = Long.parseLong(TimeUtil.dateToStampSeconds(TimeUtil.getTime(o2.getSubTime())));
                    if (time2 - time1 < 0) {
                        return 1;
                    } else if (time2 - time1 == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<LogBean.LogDetailBean>() {
                @Override
                public int compare(LogBean.LogDetailBean o1, LogBean.LogDetailBean o2) {
                    long time1 = Long.parseLong(TimeUtil.dateToStampSeconds(TimeUtil.getTime(o1.getSubTime())));
                    long time2 = Long.parseLong(TimeUtil.dateToStampSeconds(TimeUtil.getTime(o2.getSubTime())));
                    if (time2 - time1 > 0) {
                        return 1;
                    } else if (time2 - time1 == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }
    }

    public static void sortLogOperate(List<LogBean.LogDetailBean> list, boolean flag) {
        if (flag) {
            Collections.sort(list, new Comparator<LogBean.LogDetailBean>() {
                @Override
                public int compare(LogBean.LogDetailBean o1, LogBean.LogDetailBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    String name1 = o1.getOperate();
                    String name2 = o2.getOperate();
                    if (ca.compare(name2, name1) < 0) {
                        return 1;
                    } else if (ca.compare(name2, name1) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<LogBean.LogDetailBean>() {
                @Override
                public int compare(LogBean.LogDetailBean o1, LogBean.LogDetailBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    String name1 = o1.getOperate();
                    String name2 = o2.getOperate();
                    if (ca.compare(name2, name1) > 0) {
                        return 1;
                    } else if (ca.compare(name2, name1) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }
    }

    public static void sortLogNumber(List<LogBean.LogDetailBean> list, boolean flag) {
        if (flag) {
            Collections.sort(list, new Comparator<LogBean.LogDetailBean>() {
                @Override
                public int compare(LogBean.LogDetailBean o1, LogBean.LogDetailBean o2) {
                    if (o2.getCount() - o1.getCount() > 0) {
                        return 1;
                    } else if (o2.getCount() - o1.getCount() == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<LogBean.LogDetailBean>() {
                @Override
                public int compare(LogBean.LogDetailBean o1, LogBean.LogDetailBean o2) {
                    if (o2.getCount() - o1.getCount() < 0) {
                        return 1;
                    } else if (o2.getCount() - o1.getCount() == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }
    }

}
